define([],function(){
	var event = {};

	/**
	 * 轮播
	 */
	var carousel = function(i,id,w_diff,w_li){
		// 点击左右箭头
		$("#" + id).next().unbind("click");
		$("#" + id).next().click(function(){
			if( (w_li*(i+1)) < w_diff ){
				i++;
				$("#" + id + " .tab-box").animate({"marginLeft":(-w_li*i)+'px'});
			}else{
				$("#" + id + " .tab-box").animate({"marginLeft":(-w_diff)+'px'});
			}
		});
		$("#" + id).prev().unbind("click");
		$("#" + id).prev().click(function(){
			if( (w_li*(i-1)) > w_diff ){
				i = parseInt( w_diff/w_li )-1;
				$("#" + id + " .tab-box").animate({"marginLeft":(-w_diff+w_li)+'px'});
			}else if( i-1 > 0 ){
				i--;
				$("#" + id + " .tab-box").animate({"marginLeft":(-w_li*i)+'px'});
			}else{
				i = 0;
				$("#" + id + " .tab-box").animate({"marginLeft":'0px'});
			}
		});
	}

	/**
	 * 轮播初始化
	 */
	event.carouselInit = function(i,id){
		if( !id ) id = "tabShow";
		var w_li = 120;
		var w_show = $("#" + id).width();
		var $li = $("#" + id + " > ul > li");
		var w_diff = w_li * $li.length - w_show;
		if( w_diff <= 0 ){
			$("#" + id).prev().css({"display":"none"});
			$("#" + id).next().css({"display":"none"});
			$("#" + id).css({"width":"100%"});
			$("#" + id).find(".tab-box").css({"width":"100%"});
			var w = 100 / $li.length;
			$li.css({"width":w + "%"});
		}else{
			if( w_li*i < w_diff ){
				if( i > 0 ) $("#" + id + " .tab-box").stop().animate({"marginLeft":(-w_li*(i-1))+'px'});
			}else{
				$("#" + id + " .tab-box").stop().animate({"marginLeft":(-w_diff)+'px'});
			}
			carousel(i,id,w_diff,w_li);
		}
	}

	return event;
});